package com.study.springbootsecurity.exception;


import lombok.Data;

/**
 * @author huangjianyun
 * @version 1.0
 * @description: TODO 业务异常类
 * @date 2024/7/4 9:16
 */
@Data
public class BusinessException extends RuntimeException{

    private Integer errorCode= -1;

    private String errorMessage="";

    private static final Integer DEFAULT_ERROR_CODE = -1;

    public BusinessException(){
        super();
    }

    public BusinessException(String message){
        this(DEFAULT_ERROR_CODE,message);
    }

    public BusinessException(String message,Throwable cause){
        this(DEFAULT_ERROR_CODE,message,cause);
    }

    public BusinessException(Throwable cause){
        super(cause);
        this.errorMessage = cause.getMessage();
    }

    public BusinessException(Integer code,String message){
        super(message);
        this.errorCode=code;
        errorMessage=message;
    }

    public BusinessException(Integer code,String message,Throwable cause){
        super(message,cause);
        this.errorCode=code;
        errorMessage=message;
    }

    public BusinessException(ExceptionCode exceptionCode){
        this(exceptionCode.getCode(), exceptionCode.getMessage());
    }

    public BusinessException(ExceptionCode exceptionCode, Throwable cause){
        this(exceptionCode.getCode(), exceptionCode.getMessage(), cause);
    }

    public static BusinessException create(String errorMsg){
        return new BusinessException(DEFAULT_ERROR_CODE, errorMsg);
    }
}

